import React from 'react';
import { connect } from "react-redux";

export default class OrderC extends React.Component {
    constructor(props) {
        super(props);
        this.state=({
            count:0
        })
    }
    componentDidMount(){
        console.log(this.state.count);
        
        this.props.addprice(this.state.count)
    }
    render() {
        const keepTwoDecimal=(num)=>{
            var result = parseFloat(num);
            result = Math.round(num * 100) / 100;
            return result;
        }
        this.state.count=0;
        return <section className="orderC">
            <div className="order">
                <div className="banner">
                    <h3>订单详情</h3>
                    <ul>
                        {
                            this.props.orderc.map((item, idx) => {
                                let priceC = 0;
                                priceC = item.productQuantity * item.productPrice;
                                this.state.count+=priceC;
                                return <li key={idx}>
                                    <div className="product">
                                        <h4>{item.productName}</h4>
                                    </div>
                                    <div className="data">
                                        <span className="quantity">×{item.productQuantity}</span>
                                        <span className="price">￥{item.productPrice}</span>
                                    </div>
                                </li>
                            })
                        }
                        <li>
                            <h4 className="count">总计</h4>
                            <span className="countP">￥{keepTwoDecimal(this.state.count)}</span>
                        </li>
                    </ul>
                </div>
            </div>
            <div className="info">
                <div className="banner">
                    <h3>订单信息</h3>
                    <div className="time">
                        <h4>下单时间</h4>
                        <span>{this.props.createTime}</span>
                    </div>
                </div>
            </div>
        </section>
    }
}
